package com.fwj.gmall.product.controller;

import com.fwj.gmall.model.product.BaseAttrInfo;
import com.fwj.gmall.model.product.BaseAttrValue;
import com.fwj.gmall.product.service.AttrInfoService;
import com.fwj.gmall.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product/")
@Api("平台属性接口")
public class AttrController {


    @Autowired
    AttrInfoService attrInfoService;

    @ApiOperation("根据分类id获取平台属性")
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable("category1Id") Long category1Id, @PathVariable("category2Id") Long category2Id, @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> attrInfoList = attrInfoService.attrInfoList(category3Id);
        return Result.ok(attrInfoList);
    }

    @ApiOperation("添加/修改平台属性")
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        attrInfoService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @ApiOperation("根据平台属性id获取平台属性值")
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId) {
        List<BaseAttrValue> infoList = attrInfoService.getAttrValueList(attrId);
        return Result.ok(infoList);
    }

}
